<template>
  <div>
    <basic-container>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>内容审核</el-breadcrumb-item>
        <el-breadcrumb-item>作品审核</el-breadcrumb-item> 
      </el-breadcrumb> 
    </basic-container> 
    <basic-container>
      <avue-crud 
        ref="crud"
        :data="data"
        v-model="form"
        :option="option" 
        :page.sync="page"
        @on-load="getList"
        @refresh-change="refreshChange"
        @search-reset="form={}"
        @search-change="searchChange">
        <!-- 自定义 -->
        <template slot-scope="scope" slot="menuLeft">
          <br/>
          <!-- <el-tag> 已通过n条 未通过n条 待审核n条</el-tag> -->
        </template>
        
        <template slot="book_intro" slot-scope="scope">
          <el-form class="content">
            <a href="#" @click="open(scope.row.book_intro)">
              <basic-container v-html="scope.row.book_intro"> </basic-container>
            </a>
          </el-form>
        </template>
        <!-- 自定义操作栏 -->
        <template slot-scope="scope" slot="menu">
          <el-button
            icon="el-icon-primary"
            type="text"
            size="small"
            @click.stop="info(scope)"
            >查看</el-button
          >
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
import { common } from "@/api/cat/httpRequest";
import { catUrl } from "@/config/env";
import { appBookCheck as baseURL,uploadFile , bookCategory} from "@/api/cat/baseUrls";
export default {
  data() {
    return {
      page: {
        total: 0,
        pageSize: 10
      },
      default: {
        orderByList: "state&ASC,edit_time&DEsc",
        // state : "$in1,2,3"
      },
      type: true,
      data: [],
      params: {},
      form: {},
      option: {
        addBtn: false,
        editBtn: false,
        viewBtn: false,
        delBtn: false,
        excelBtn: true,
        selection: true,
        border: true,
        border: true,
        // editBtnText:'审核',
        column: [
          {
            label: "日期",
            prop: "create_time",
            type: "daterange",
            search: true
          },
          {
            label: "用户id",
            prop: "user_id",
            type: "input",
            search: true,
          },
          {
            label: "用户昵称",
            prop: "author_name",
            type: "input",
            search: true,
          },
          {
            label: "书籍id",
            prop: "book_id",
            type: "input",
            search: true,
          },
          {
            label: "书籍名称",
            prop: "book_title",
            type: "input",
            search: true,
          }, 
          {
            label: "分类",
            prop:'category_id_1',
            type: "select",
            search: false,
            dicUrl: `${catUrl + bookCategory.getListByLeave}/1`,
            dicFormatter: (res) => {
              return res.source;
            },
            props: {
              label: "label",
              value: "value",
            },
          },
          {
            label: "标签",
            prop: "plotlabel",
            type: "input",
            search: true,
          },
          
          {
            label: "书籍简介",
            prop: "book_intro",
            type: "input",
            search: true,
            slot:true,
            addDisplay: false,
            editDisplay: false,
            addDisabled: false,
            editDisabled: false,
            width:'120px',
          }, 
          {
            label: "审核状态",
            prop: "state",
            type: "select",
            hide: false,
            search: false,
            dicData: [
              {
                label: "<font style='color:red'>待审核</font>",
                value: 1,
              },
              {
                label: "已通过",
                value: 2,
              },
              {
                label: "未通过",
                value: 3,
              },
            ],
          },
          {
            label: "审核状态",
            prop: "states",
            type: "select",
            hide: true,
            search: true,
            dicData: [
              {
                label: "待审核",
                value: 1,
              },
              {
                label: "已通过",
                value: 2,
              },
              {
                label: "未通过",
                value: 3,
              },
            ],
            addDisplay: false,
            editDisplay: false,
            addDisabled: false,
            editDisabled: false,
          },
          {
            label: "最后操作信息",
            prop: "edit_time",
            type: "date",
            addDisplay: false,
            editDisplay: false,
            addDisabled: false,
            editDisabled: false,
          },
        ],
      },
    };
  },
  methods: {
    async getList(){
      this.loading = true;
      //清空表格列表
      this.data = [];
      //发送请求获取数据
      let response = await common(
        baseURL.pageAndParam,
        {...this.params,...this.default},
        this.page,
        "POST"
      );
      this.page = response.page;
      this.data = response.data;
      this.loading = false;
    },
    //查看详情
    info(scope) {
      this.$router.push("/works/worksinfo?book_id="+scope.row.id)
    },
    /**刷新 */
    refreshChange() {
      this.getList();
    },
    /**搜索 */
    searchChange(params, done) { 
      params.book_title = `%${params.book_title ? params.book_title : ""}%`;
      params.create_time = `${params.create_time ? "!<>!" + params.create_time : ""}`
      params.state = params.states;
      delete params.states;
      this.params = params;
      this.page.currentPage = 1;
      this.getList();
      if (done) done();
    },
    open(content) {
      console.log(content);
      this.$notify({
        title: "评论内容",
        dangerouslyUseHTMLString: true,
        message: `<strong>${content}</strong>`,
      });
    },
  },
  watch: {
      '$route' () {
		  this.getList();
        // this._initData();//我的初始化方法
      }
    },
};
</script>
<style>
.content .basic-container {
  overflow: auto;
  height: 100px;
}
</style>